package com.buho29.rcmanager.utils;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.Gravity;
import android.widget.Toast;

import com.buho29.rcmanager.R;

public class Make {

	public static Toast toast(Context context,CharSequence charSequence) {
		Toast t = Toast.makeText(context,charSequence,Toast.LENGTH_LONG); 
        t.setGravity(Gravity.CENTER, 0,0);
		return t;
	}
	
	public static SpannableStringBuilder appendResult(SpannableStringBuilder ss, CharSequence field, Object value,String sep,int color) {
        
        int end ;
        int start = ss.length();
        ss.append(field+": ");
        end = ss.length();
        ss.setSpan(new StyleSpan(Typeface.BOLD), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(color), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.append(String.valueOf(value)+sep);
        return ss;
	}
	
	public static SpannableStringBuilder appendResult1(SpannableStringBuilder ss, CharSequence field, Object value,String sep,int color) {
        
        int end ;
        int start = ss.length();
        ss.append(field+": ");
        end = ss.length();
        ss.setSpan(new StyleSpan(Typeface.BOLD), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        start = ss.length();
        ss.append(String.valueOf(value)+sep);
        end = ss.length();
        ss.setSpan(new ForegroundColorSpan(color), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return ss;
	}
	
	public static SpannableStringBuilder appendResult(SpannableStringBuilder ss, CharSequence field, Object value,String sep) {
        
        int end ;
        int start = ss.length();
        ss.append(field+": ");
        end = ss.length();
        ss.setSpan(new StyleSpan(Typeface.BOLD), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        
        ss.append(String.valueOf(value)+sep);
        return ss;
	}
	
	public static SpannableStringBuilder buildResult(SpannableStringBuilder ss,String[] fields,Object[] value,String sep) {
		
		for (int i = 0; i < value.length; i++) {
			appendResult(ss, fields[i], value[i], sep);
		}
		ss.delete(ss.length()-1, ss.length());
		return ss;
		
	}
	
	public static Builder dialogConfirm(Context context,String title) {
    	return new AlertDialog.Builder(context)
		.setIcon(R.drawable.alert_dialog_icon)
        .setTitle(title)
        .setNegativeButton(R.string.cancel, null);
	}
	
    public static String NEWLINE = "\n";
    public static String SEP = ", ";
}
